#pragma once

#include <iostream>
#include <string>

#include <boost/asio/buffer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/write.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/function.hpp>

#include "socket_session.h"

namespace Socket
{
class SocketSession;

// Client 基类，通讯模块需要继承，然后重写Write和ReadCallback方法。
class SocketClientInterface : virtual public SocketInterface
{
public:
    SocketClientInterface(const std::string ip, const unsigned short port);
    // SocketClientInterface();
    virtual ~SocketClientInterface();

    void Start();
    void AsyncConnect();
    void StartRead();
    void Stop();

    virtual void OnConnectStatus(bool *isConnected, boost::system::error_code *ec) 
    {
        printf("SocketClient Connect Callback() --> %d, %s\n", *isConnected, ec->message().c_str());
    };
    virtual void ReadCallback(std::string *str_read, boost::system::error_code *ec)
    {
        printf("SocketClient Read Callback() --> %s, %s\n", (*str_read).c_str(), ec->message().c_str());
    };
    virtual void HandleWrite(std::size_t *length, boost::system::error_code *ec) 
    {
        printf("SocketClient Write Callback() --> %ld, %s\n", *length, ec->message().c_str());
    };
    virtual bool WriteSome(std::string &str_write) {return true;};
private:
    std::string str_read_;
    std::string str_write_;
    boost::system::error_code error_code_;

    std::string server_ip_;
    unsigned short server_port_;
    
    // boost::asio::ip::tcp::resolver r;
    boost::asio::ip::tcp::resolver::results_type endpoints_;

    boost::shared_ptr<SocketSession> ptr_session_;
    boost::shared_ptr<boost::asio::io_service> m_ios_executors_;
    boost::shared_ptr<boost::asio::io_service::work> m_ios_work_acceptors_;
};
};